package demo.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动,可写可不写
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取链接
        String url="jdbc:mysql://127.0.0.1:3306/db1";
        String username="root";
        String password="123456";
        //注册驱动
        //获取链接
        //是一个接口！！！强制别人使用某种格式
        Connection connection = DriverManager.getConnection(url,username, password);
        //3.定义SQL语句
        //String sql="UPDATE tset SET money=2000 WHERE id=1";
        String sql="UPDATE tset SET money=1000 WHERE name='小明'";
        //4.获取SQL的执行对象statement
        Statement statement = connection.createStatement();
        //5.使用对象执行SQL，并返回结果
        int i = statement.executeUpdate(sql);
        System.out.println(i);
        //6.关闭释放资源

        statement.close();
        connection.close();

    }
}
